package SV_PASSWD_PLAIN_HC;

import org.jasypt.encryption.pbe.StandardPBEStringEncryptor;
import org.jasypt.iv.RandomIvGenerator;
import org.jasypt.properties.EncryptableProperties;

import java.io.FileInputStream;
import java.io.IOException;
import java.util.Properties;

public class Fixed {
    void test()

    {
        /*
         * First, create (or ask some other component for) the adequate encryptor for
         * decrypting the values in the .properties file.
         */
        StandardPBEStringEncryptor encryptor = new StandardPBEStringEncryptor();
        encryptor.setPassword("jasypt"); // could be obtained from the web, env variable, etc
        encryptor.setAlgorithm("PBEWithHMACSHA512AndAES_256");
        encryptor.setIvGenerator(new RandomIvGenerator());

        /*
         * Create an EncryptableProperties object and load it the usual way.
         */
        Properties props = new EncryptableProperties(encryptor);
        try {
            props.load(new FileInputStream("/path/to/my/configuration.properties"));
        } catch (IOException e) {
            throw new RuntimeException(e);
        }

        /*
         * To get an encrypted value, do exactly the same. Decryption will
         * be transparently performed behind the scenes.
         */
        String datasourcePassword = props.getProperty("datasource.password");
    }
}
